package cn.com.klun.tjy.other.hyperloglog;

public class Hll1 {
    private long m;
    private long b;

    /**
     * 求指数
     * @param a
     * @param b
     * @return
     */
    public long exponent(long a,long b){
        long temp = a;
        for (int i = 0; i < b; i++) {
            a = a*temp;
        }
        return a;
    }
    public double getNum(long m){
        if(m == 16){
            return 0.673;
        }
        if(m == 32){
            return 0.697;
        }
        if(m == 64){
            return 0.709;
        }
        return 0.7213/(1+1.079/m);
    }
    public void amendment(double alpha ,long m,long register){
//        double DV_est = alpha * m^2 * 1/sum(2^ -register);
    }
    public static void main(String[] args) {
//
//        registersisters = [0]*m   # initialize m registers to 0
//
//###########################################################################
//# Construct the HLL structure
//        for h in hashed(data):
//        register_index = 1 + get_register_index( h,b )        # binary address of the rightmost b bits
//                run_length = run_of_zeros( h,b )              # length of the run of zeroes starting at bit b+1
//        registers[ register_index ] = max( registers[ register_index ], run_length )
//
//##########################################################################
//# Determine the cardinality
//                DV_est = alpha * m^2 * 1/sum( 2^ -register )  # the DV estimate
//
//        if DV_est < 5/2 * m:                                  # small range correction
//                V = count_of_zero_registers( registers )      # the number of registers equal to zero
//        if V == 0:                                            # if none of the registers are empty, use the HLL estimate
//                DV = DV_est
//    else:
//        DV = m * log(m/V)                                     # i.e. balls and bins correction
//
//        if DV_est <= ( 1/30 * 2^32 ):                         # intermediate range, no correction
//                DV = DV_est
//        if DV_est > ( 1/30 * 2^32 ):                          # large range correction
//                DV = -2^32 * log( 1 - DV_est/2^32)
    }





//    m = 2^b                                                   # with b in [4...16]
//
//            if m == 16:
//    alpha = 0.673
//    elif m == 32:
//    alpha = 0.697
//    elif m == 64:
//    alpha = 0.709
//            else:
//    alpha = 0.7213/(1 + 1.079/m)
//
//    registers = [0]*m   # initialize m registers to 0
//
//  ###########################################################################
//            # Construct the HLL structure
//for h in hashed(data):
//    register_index = 1 + get_register_index( h,b ) # binary address of the rightmost b bits
//            run_length = run_of_zeros( h,b ) # length of the run of zeroes starting at bit b+1
//    registers[ register_index ] = max( registers[ register_index ], run_length )
//
//##########################################################################
//        # Determine the cardinality
//            DV_est = alpha * m^2 * 1/sum( 2^ -register )  # the DV estimate
//
//if DV_est < 5/2 * m: # small range correction
//            V = count_of_zero_registers( registers ) # the number of registers equal to zero
//    if V == 0:  # if none of the registers are empty, use the HLL estimate
//            DV = DV_est
//    else:
//    DV = m * log(m/V)  # i.e. balls and bins correction
//
//if DV_est <= ( 1/30 * 2^32 ):  # intermediate range, no correction
//            DV = DV_est
//if DV_est > ( 1/30 * 2^32 ):  # large range correction
//            DV = -2^32 * log( 1 - DV_est/2^32)
}
